package com.tsmti.core.common.query.data;

import java.io.Serializable;
import java.util.List;

/**
 * @Package：com.tsmti.core.query.data
 * @Class：PageJson
 * @Description： TODO
 * @Author：zcw
 * @Date：Created in 2018/3/24 12:47
 * @Company:
 * @Version：
 * @Modified By:
 */
public class PageJson<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 当前页
     */
    private long page = 1;
    /**
     * 每页显示记录数
     */
    private long rows = 10;
    /**
     * 总数
     */
    private long total;
    /**
     * 总页数
     */
    private long totalPages;
    /**
     * 结果
     */
    private List<T> results;

    public PageJson() {

    }

    public PageJson(List<T> results) {
        this(0, results.size(), results.size(), results);
    }

    public PageJson(Page<T> page) {
        this(page.getNumber(), page.getSize(), page.getTotalElements(), page.getContent());
    }

    public PageJson(long page, long rows, long total, List<T> results) {
        this.page = page;
        this.rows = rows;
        this.total = total;
        this.results = results;
        this.totalPages = getRows() == 0 ? 1 : (int) Math.ceil((double) total / (double) getRows());
    }

    public long getPage() {
        return page;
    }

    public void setPage(long page) {
        this.page = page;
    }

    public long getRows() {
        return rows;
    }

    public void setRows(long rows) {
        this.rows = rows;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public long getTotalPages() {
        return totalPages;
    }

    public List<T> getResults() {
        return results;
    }

    public void setResults(List<T> results) {
        this.results = results;
    }
}
